import java.util.Scanner;
import java.io.RandomAccessFile;
import java.io.*;
import java.util.*;

public class sseditor {
	private final static int OFFSET = 0x121F9;
	private final static int GIL_OFFSET = 0x12459;

	private RandomAccessFile file;
	private byte[] CharArray;
	private byte[] gil;

	private long charOffset;

	private int maxMP;
	private int currentMP;

	public sseditor() throws FileNotFoundException {
		gil = new byte[2];
		CharArray = new byte[37];
	}

    public void SetOffset(String Character) {
		charOffset = -1;
	    switch(Character) {
		    case "Tina": charOffset = 0; break;
		    case "Lock": charOffset = 1 * 0x25; break;
		    case "Cayene": charOffset = 2 * 0x25; break;
		    case "Shadow": charOffset = 3 * 0x25; break;
		    case "Edgar": charOffset = 4 * 0x25; break;
		    case "Mash": charOffset = 5 * 0x25; break;
		    case "Celes": charOffset = 6 * 0x25; break;
		    case "Strago": charOffset = 7 * 0x25; break;
		    case "Relm": charOffset = 8 * 0x25; break;
		    case "Setzer": charOffset = 9 * 0x25; break;
		    case "Mog" : charOffset = 10 * 0x25; break;
		    case "Gau": charOffset = 11 * 0x25; break;
		    case "Gogo": charOffset = 12 * 0x25; break;
		    case "Umaro": charOffset = 13 * 0x25; break;
    	}
    }

    public void fileRead(String path) throws IOException {
    	file = new RandomAccessFile(path, "rw");
    	file.seek(OFFSET + charOffset);
		file.readFully(CharArray);
		file.seek(GIL_OFFSET);
		file.readFully(gil);
    }

    public long getGil() {
    	return (((gil[1] << 8) | gil[0]) & 0xFFFF);
    }

    public void setGil(int g) {
    	gil[0] = (byte)(g & 0xFF);
    	gil[1] = (byte)((g >> 8) & 0xFF);
    }

    public String getCharName() {    	
		String CharName = "";

		byte[] CharNameArray = new byte[6];
		for (int i = 0; i < CharNameArray.length; i++) {
	    	CharNameArray[i] = CharArray[2+i];
		}
		for (byte i: CharNameArray) {
	    	if (i != (byte)0xFF)
				CharName += (char)((byte)(i - 0x1F)); // convert to letters
		}
		return CharName;
    }

    public int getLevel() {
    	return (int)CharArray[8];
    }

    public int getHP() { // returns current HP
    	return (int)(((CharArray[10] & 0xFF) << 8) | (CharArray[9] & 0xFF));
    }
    
    public int getMaxHP() {
		int maxHP = (int)(((CharArray[12] & 0x0F) << 8) | (CharArray[11] & 0xFF));
		int modify = (int)(CharArray[12] & 0xF0) >> 4;
		switch(modify) {
			case 0x0: maxHP += 0; break;
			case 0x1: maxHP += 4096; break;
			case 0x2: maxHP += 8192; break;
			case 0x4: maxHP += (maxHP >> 2); break;
			case 0x5: maxHP += (int)(((CharArray[12] << 6) & 0x1FC0) | ((CharArray[11] >> 2) & 0x3F));  break;
			case 0x8: maxHP += (maxHP/2); break;
			case 0x9: maxHP += (6144 + (maxHP/2)); break;
			case 0xC: maxHP += (maxHP / 8); break;
			case 0xD: maxHP += (4608 + (maxHP / 8)); break;
			case 0xE: maxHP += (9216 + (maxHP / 8)); break;
			default: maxHP = 9999; break;
		}

		if (maxHP > 9999)
		    maxHP = 9999;

		return maxHP;
	}

	public int getMP(){ // get maxMP first.
		currentMP = 0;
		if (maxMP > 0)
			currentMP = (int)(((CharArray[14] & 0xFF) << 8) | (CharArray[13] & 0xFF));
		return currentMP;
	}

	public int getMaxMP() {
		maxMP = (int)(((CharArray[16] & 0x0F) << 8) | (CharArray[15] & 0xFF));
		int modify = (int)(CharArray[16] & 0xF0) >> 4;
		switch(modify) {
		case 0x4: maxMP += maxMP >> 2; break;
		case 0x8: maxMP += (maxMP / 2); break;
		case 0xC: maxMP += (maxMP / 8); break;
		default: maxMP += 0; break;
		}

		if (maxMP == 0) // character does not have MP
			currentMP = 0;

		if (maxMP > 999)
		    maxMP = 999;

		return maxMP;
	}

	public int getExp() {
		return (int)((CharArray[17] & 0xFF) | ((CharArray[18] & 0xFF) << 8) | ((CharArray [19] & 0xFF) << 16));
	}

	public int getStrength() {
		return CharArray[26] & 0xFF;
	}

	public int getSpeed() {
		return CharArray[27] & 0xFF;
	}
	
	public int getVitality() {
		return CharArray[28] & 0xFF;
	}
	
	public int getMagic() {
		return CharArray[29] & 0xFF;
	}
	
    public byte printStatus() {
    	return CharArray[20];
    }

    public void setStatus(byte statusByte) {
    	CharArray[20] = statusByte;
    }

    public boolean getFloat() {
		return (CharArray[21] >= (byte)0x80 && CharArray[21] <= (byte)0xFF);
    }

    public void setFloat(boolean set) {
    	if (set)
    		CharArray[21] = (byte)(CharArray[21] | 0x80);
    	else
    		CharArray[21] &= (byte)0x00;
    }
 
    public void setEsper(String esper) {
		if(esper.equals("None"))
			CharArray[30] = (byte)0xFF;
		else
			for (byte b = (byte)0x00; b <= (byte)0x1A; b++) {
				if(esper.equals(readEsper(b)))
					CharArray[30] = b;
			}
    }

    public String readEsper(byte b) {
		String result = "";
		switch(b) {
			case 0x00: result = "Ramuh"; break;
			case 0x01: result = "Ifrit"; break;
			case 0x02: result = "Shiva"; break;
			case 0x03: result = "Siren"; break;
			case 0x04: result = "Terrato"; break;
			case 0x05: result = "Maduin"; break;
			case 0x06: result = "Shoat"; break;
			case 0x07: result = "Bismark"; break;
			case 0x08: result = "Stray"; break;
			case 0x09: result = "Palidor"; break;
			case 0x0A: result = "Tritoch"; break;
			case 0x0B: result = "Odin"; break;
			case 0x0C: result = "Raiden"; break;
			case 0x0D: result = "Bahamut"; break;
			case 0x0E: result = "Alexandr"; break;
			case 0x0F: result = "Crusader"; break;
			case 0x10: result = "Ragnarok"; break;
			case 0x11: result = "Kirin"; break;
			case 0x12: result = "Zoneseek"; break;
			case 0x13: result = "Carbunkl"; break;
			case 0x14: result = "Phantom"; break;
			case 0x15: result = "Sraphim"; break;
			case 0x16: result = "Golem"; break;
			case 0x17: result = "Unicorn"; break;
			case 0x18: result = "Fenrir"; break;
			case 0x19: result = "Startlet"; break;
			case 0x1A: result = "Phoenix"; break;
			default: result = "None"; break;
		}
		return result;
    }

    public String getEsper() {
		return readEsper(CharArray[30]);
    }

    public String getRightItem() {
    	return ItemRead((int)(CharArray[31] & 0xFF));
    }

    public void setRightItem(String item) {
    	if (item.equals("EMPTY"))
    		CharArray[31] = (byte)0xFF;
		else {
		    for (int b = 0; b < 90; b++) { // only weapons
				if (item.equals(ItemRead(b)))
				    CharArray[31] = (byte)(b);
	    	}
    	}
    }

    public String getLeftItem() {
    	return ItemRead((int)(CharArray[32] & 0xFF));
    }

    public void setLeftItem(String item) {
    	if(item.equals("EMPTY"))
    		CharArray[32] = (byte)0xFF;
    	else {
    		for (int b = 0; b < 105; b++) { //only weapons and shields
				if(item.equals(ItemRead(b)))
					CharArray[32] = (byte)(b);
			}
    	}
    }

    public String getHelmetItem() {
    	return ItemRead((int)(CharArray[33] & 0xFF));
    }

    public void setHelmetItem(String item) {
    	if (item.equals("EMPTY"))
            CharArray[33] = (byte)0xFF;
		else {
            for(int b = 105; b < 132; b++) { // helmets only
				if (item.equals(ItemRead(b)))
                    CharArray[33] = (byte)(b);
            }
		}
    }

    public String getArmorItem() {
    	return ItemRead((int)(CharArray[34] & 0xFF));
    }

    public void setArmorItem(String item){
    	if (item.equals("EMPTY"))
            CharArray[34] = (byte)0xFF;
		else {
            for(int b = 132; b < 163; b++) {
				if (item.equals(ItemRead(b)))
                CharArray[34] = (byte)(b);
            }
		}
    }

    public String getRelic1Item() {
    	return ItemRead((int)(CharArray[35] & 0xFF));
    }

    public void setRelic1Item(String item){
		if (item.equals("EMPTY"))
            CharArray[35] = (byte)0xFF;
		else {
            for(int b = 176; b < 231; b++) {
				if (item.equals(ItemRead(b)))
                	CharArray[35] = (byte)(b);
            }
		}
	}

    public String getRelic2Item() {
    	return ItemRead((int)(CharArray[36] & 0xFF));
    }

    public void setRelic2Item(String item){
		if (item.equals("EMPTY"))
            CharArray[36] = (byte)0xFF;
		else {
            for(int b = 176; b < 231; b++) {
				if (item.equals(ItemRead(b)))
                	CharArray[36] = (byte)(b);
            }
		}
	}

    public String ItemRead(int b) {
		String output = "";
		switch(b) {
			    // Dirk
			case 0x00: output = "Dagger"; break;
			case 0x01: output = "Mithril Knife"; break;
			case 0x02: output = "Main Gauche"; break; // Randomly evades enemy attacks
			case 0x03: output = "Air Knife"; break; // Wind-elemental
			case 0x04: output = "Thief's Knife"; break; // Randomly steals items
			case 0x05: output = "Assassin Dagger"; break; // Randomly kills target instantly
			case 0x06: output = "Man Eater"; break; // Deals double damage to human enemies
			case 0x07: output = "Sword Breaker"; break; // Randomly evades enemy attacks
			case 0x08: output = "Gladius"; break; // Holy-elemental
			case 0x09: output = "Valiant Knife"; break; // When HP is low, attack power rises
			    // Sword
			case 0x0A: output = "Mithril Sword"; break;
			case 0x0B: output = "Great Sword"; break;
			case 0x0C: output = "Rune Blade"; break; // Consumes MP to perform critical hits
			case 0x0D: output = "Flame Tongue"; break; // Randomly casts "Fire" when attacking
			case 0x0E: output = "Ice Brand"; break; // Randomly casts "Blizzard" when attacking
			case 0x0F: output = "Thunder Blade"; break; //Randomly casts "Thunder" when attacking
			case 0x10: output = "Bastard Sword"; break;
			case 0x11: output = "Break Blade"; break; // Randomly casts "Break" when attacking
			case 0x12: output = "Blood Sword"; break; // Absorbs part of damage as HP
			case 0x13: output = "Enhance Sword"; break; // Raises Magic when equipped
			case 0x14: output = "Crystal Sword"; break;
			case 0x15: output = "Falchion"; break;
			case 0x16: output = "Soul Saber"; break; // Absorbs part of damage as MP | Randomly casts "Death" when attacking
			case 0x17: output = "Ogre Nix"; break; // Uses MP to perform critical hits | If you're unlucky, it will break
			case 0x18: output = "Excalibur"; break; // A holy sword
			case 0x19: output = "Zantetsuken"; break; // Randomly severs target enemy
			case 0x1A: output = "Lightbringer"; break; // A legendary sword of the gods
			case 0x1B: output = "Ragnarok"; break; // Randomly casts "Flare" when attacking
			case 0x1C: output = "Ultima Weapon"; break; // Weapon grows in power as level & HP raise
			    // Lance
			case 0x1D: output = "Mitril Spear"; break;
			case 0x1E: output = "Trident"; break;
			case 0x1F: output = "Heavy Lance"; break;
			case 0x20: output = "Partisan"; break;
			case 0x21: output = "Holy Lance"; break; // Randomly casts "Holy" when attacking
			case 0x22: output = "Golden Spear"; break;
			case 0x23: output = "Glow Lance"; break;
			case 0x24: output = "Sagojou's Spear"; break; // If equipped while in Kappa status...
			    //Dirk
			case 0x25: output = "Kunai"; break;
			case 0x26: output = "Kodachi"; break;
			case 0x27: output = "Sakurafubuki"; break;
			case 0x28: output = "Piercing Katana"; break;
			case 0x29: output = "Ichigeki"; break; // Randomly slays an enemy in one blow
			case 0x2A: output = "Kagenui"; break; // Randomly casts "Stop" when attacking
			    //Knife
			case 0x2B: output = "Ashura"; break;
			case 0x2C: output = "Kotetsu"; break;
			case 0x2D: output = "Kikuichimonji"; break;
			case 0x2E: output = "Kazekiri Blade"; break; // Randomly causes "Wind Slash" when attacking
			case 0x2F: output = "Murasame"; break;
			case 0x30: output = "Masamune"; break;
			case 0x31: output = "Heaven's Cloud"; break;
			case 0x32: output = "Mutsu no Kami"; break;
			    //Rod
			case 0x33: output = "Heal Rod"; break; // Recovers lost HP of allies
			case 0x34: output = "Mithril Rod"; break;
			case 0x35: output = "Flame Rod"; break; // Casts "Fira" when used as an item, then breaks
			case 0x36: output = "Ice Rod"; break; // Casts "Blizzara" when used as an item, then breaks
			case 0x37: output = "Thunder Rod"; break; // Casts "Thundara" when used as an item, then breaks
			case 0x38: output = "Poison Rod"; break; // Casts "Poison" when used as an item, then breaks
			case 0x39: output = "Holy Rod"; break; // Casts "Holy" when used as an item, then breaks
			case 0x3A: output = "Gravity Rod"; break; // Casts "Graviga" when used as an item, then breaks
			case 0x3B: output = "Punisher"; break; // Consumes MP to perform critical hits
			case 0x3C: output = "Wizard Rod"; break; // Raises Magic when equipped
			    //Brush
			case 0x3D: output = "Chocobo Brush"; break;
			case 0x3E: output = "Da Vinci Brush"; break;
			case 0x3F: output = "Magical Brush"; break;
			case 0x40: output = "Rainbow Brush"; break;
			    //Stars
			case 0x41: output = "Shuriken"; break; // Can be used with the "Throw" command
			case 0x42: output = "Demon Wind Shuriken"; break; // Can be used with the "Throw" command
			case 0x43: output = "Windmill"; break; // Can be used with the "Throw" command
			    //Special
			case 0x44: output = "Chain Flail"; break; // Same damage dealt from the back row
			case 0x45: output = "Full Moon"; break; // Same damage dealt from the back row
			case 0x46: output = "Morning Star"; break; // Same damage dealt from the back row
			case 0x47: output = "Boomerang"; break; // Same damage dealt from the back row
			case 0x48: output = "Rising Sun"; break; // Same damage dealt from the back row
			case 0x49: output = "Hawk Eye"; break; // Same damage dealt from the back row
			case 0x4A: output = "Bone Club"; break; // It's beautifully carved
			case 0x4B: output = "Sniper"; break; // Same damage dealt from the back row
			case 0x4C: output = "Wing Edge"; break; // Same damage dealt from the back row | Randomly kills target instantly
			    //Gambler
			case 0x4D: output = "Card"; break;
			case 0x4E: output = "Darts"; break;
			case 0x4F: output = "Death Card"; break; // Randomly casts "Death" when attacking
			case 0x50: output = "Intense Darts"; break; // Randomly slays an enemy in one blow
			case 0x51: output = "Dice"; break;
			case 0x52: output = "Fake Dice"; break;
			    //Claw
			case 0x53: output = "Metal Knuckle"; break;
			case 0x54: output = "Mithril Claw"; break;
			case 0x55: output = "Kaiser Claw"; break;
			case 0x56: output = "Dark Claw"; break; // Randomly causes poisoning
			case 0x57: output = "Burning Knuckle"; break; // Randomly casts "Fire" when attacking
			case 0x58: output = "Dragon Claw"; break; // Holy-elemental
			case 0x59: output = "Tiger Fang"; break; 
			    //Shield
			case 0x5A: output = "Buckler"; break;
			case 0x5B: output = "Large Shield"; break;
			case 0x5C: output = "Mithril Shield"; break;
			case 0x5D: output = "Gold Shield"; break;
			case 0x5E: output = "Aegis Shield"; break; // Randomly evades enemy magic attacks
			case 0x5F: output = "Diamond Shield"; break;
			case 0x60: output = "Flame Shield"; break; // Absorbs fire-elemental attacks
			case 0x61: output = "Ice Shield"; break; // Absorbs cold-elemental attacks
			case 0x62: output = "Thunder Shield"; break; // Absorbs thunder-elemental attacks
			case 0x63: output = "Crystal Shield"; break;
			case 0x64: output = "Genji Shield"; break;
			case 0x65: output = "Shell Shield"; break; // If equipped while in Kapppa status...
			case 0x66: output = "Bloodstained Shield"; break; // Is cursed
			case 0x67: output = "Hero Shield"; break; // A shield in which a hero's spirit dwells
			case 0x68: output = "Force Shield"; break; // A shield which blocks only magic
			    //Helmet
			case 0x69: output = "Leather Hat"; break; 
			case 0x6A: output = "Hairband"; break;
			case 0x6B: output = "Feathered Hat"; break;
			case 0x6C: output = "Beret"; break; // "Sketch" success rate up
			case 0x6D: output = "Triangular Hat"; break;
			case 0x6E: output = "Bandana"; break;
			case 0x6F: output = "Iron Helm"; break;
			case 0x70: output = "Hypno Crown"; break; // "Manipulate" success rate up
			case 0x71: output = "Reason Hat"; break; // Raises MP by a little bit
			case 0x72: output = "Green Beret"; break; // Raises HP by a little bit
			case 0x73: output = "Head Band"; break;
			case 0x74: output = "Mithril Helm"; break;
			case 0x75: output = "Tiara"; break;
			case 0x76: output = "Gold Helm"; break;
			case 0x77: output = "Tiger Mask"; break;
			case 0x78: output = "Red Cap"; break; // Raises HP by 25%
			case 0x79: output = "Mystery Veil"; break;
			case 0x7A: output = "Circlet"; break;
			case 0x7B: output = "Royal Crown"; break;
			case 0x7C: output = "Diamond Helmet"; break;
			case 0x7D: output = "Black Hood"; break;
			case 0x7E: output = "Crystal Helm"; break;
			case 0x7F: output = "Oath Veil"; break;
			case 0x80: output = "Cat Ear Hood"; break; // Allows the wearer to find more Gil after battle
			case 0x81: output = "Genji Helmet"; break;
			case 0x82: output = "Thorn Crown"; break; // A crown of thorns worn about the head; painful
			case 0x83: output = "Dish"; break; // If equipped while in Kappa status...
			    //Armor
			case 0x84: output = "LeatherArmor"; break;
			case 0x85: output = "Cotton Robe"; break;
			case 0x86: output = "Kempo Gear"; break;
			case 0x87: output = "Iron Armor"; break;
			case 0x88: output = "Silk Robe"; break;
			case 0x89: output = "Mithril Plate"; break;
			case 0x8A: output = "Shinobi Gear"; break;
			case 0x8B: output = "White Dress"; break;
			case 0x8C: output = "Mithril Mail"; break;
			case 0x8D: output = "Earth Gear"; break; // Absorbs earth-elemental attacks
			case 0x8E: output = "Mirage Vest"; break; // Generates a mirage when worn
			case 0x8F: output = "Gold Armor"; break; 
			case 0x90: output = "Strength Vest"; break;
			case 0x91: output = "Light Robe"; break;
			case 0x92: output = "Diamond Breastplate"; break;
			case 0x93: output = "Red Jacket"; break; // The spirit of a legendary grappler dwells within
			case 0x94: output = "Force Armor"; break; // Armor with high Magic Defense power
			case 0x95: output = "Diamond Armor"; break;
			case 0x96: output = "Black Clothes"; break;
			case 0x97: output = "Comradeship Robe"; break;
			case 0x98: output = "Crystal Armor"; break;
			case 0x99: output = "Princess Gown"; break;
			case 0x9A: output = "Genji Armor"; break;
			case 0x9B: output = "Kappa Armor"; break; // If equipped while in Kappa status...
			case 0x9C: output = "Minerva Bustier"; break; // Raises MP by 25%
			case 0x9D: output = "Kitty Suit"; break; // A suit designed to look like a tigercat
			case 0x9E: output = "Chocobo Suit"; break; // Makes you feel like a chocobo
			case 0x9F: output = "Moglie Suit"; break; // Looks like a Moglie, kupo
			case 0xA0: output = "Nutkin Suit"; break; // A suit designed to look like a big squirrel
			case 0xA1: output = "Behemoth Suit"; break; // Made from Behemoth fur
			case 0xA2: output = "Snow Muffler"; break; // Made from soft hair; it's warm
			    //Tool
			case 0xA3: output = "Blast Voice"; break; // Causes confusion | Used via the "Machine" command
			case 0xA4: output = "Bio Blast"; break; // Causes poison damage | Used via the "Machine" command
			case 0xA5: output = "Sun Beam"; break; // Causes darkness & damage | Used via the "Machine" command
			case 0xA6: output = "Chainsaw"; break; // Saws the enemy to bits | Used via the "Machine" command
			case 0xA7: output = "Weak Maker"; break; // Makes a new weak point | Used via the "Machine" command
			case 0xA8: output = "Drill"; break; // Ignores defense, damages enemy | Used via the "Machine" command
			case 0xA9: output = "Air Anchor"; break; // Causes an enemy to destroy itself| Used via the "Machine" command
			case 0xAA: output = "Auto Bow Gun"; break; // A bowgun is fired | Used via the "Machine" command
			    //Skean
			case 0xAB: output = "Katon"; break; // Damages all enemies with flames | Used via "Throw" command
			case 0xAC: output = "Suiton"; break; // Damages all enemies with water | Used via "Throw" command
			case 0xAD: output = "Raijin"; break; // Damages all enemies with thunder | Used via "Throw" command
			case 0xAE: output = "Fading Leaves"; break; // Makes the user invisible | Used via the "Throw" command
			case 0xAF: output = "Dark Matter"; break; // Makes a mirage of the user | Used via the "Throw" command
			    //Relic
			case 0xB0: output = "Silver Glasses"; break; // Prevents "Darkness"
			case 0xB1: output = "Star Pendant"; break; // Prevents "Poison"
			case 0xB2: output = "Peace Ring"; break; // Prevents "Confusion" & "Berserk"
			case 0xB3: output = "Amulet"; break; // Prevents "Poison", "Zombie", & "Darkness"
			case 0xB4: output = "White Cape"; break; // Prevents "Kappa" & "Silence"
			case 0xB5: output = "Jewel Ring"; break; // Prevents "Petrification"
			case 0xB6: output = "Fairy Ring"; break; // Prevents "Poison" & "Darkness"
			case 0xB7: output = "Barrier Ring"; break; // Casts "Shell" when wearer is near death
			case 0xB8: output = "Mithril Glove"; break; // Casts "Protect" when wearer is near death
			case 0xB9: output = "Protect Ring"; break; // Automatically casts "Protect"
			case 0xBA: output = "Hermes Shoes"; break; // Automatically casts "Haste"
			case 0xBB: output = "Reflect Ring"; break; // Automatically casts "Reflect"
			case 0xBC: output = "Angel Feathers"; break; // Automatically casts "Levitate"
			case 0xBD: output = "Angel Ring"; break; // Automatically casts "Regene"
			case 0xBE: output = "Knight's Code"; break; // Protects allies who are near death
			case 0xBF: output = "Dragon Knight Boots"; break; // Change the command "Attack" to "Jump"
			case 0xC0: output = "Wind Mantle"; break; // Makes it easier to evade enemy attacks
			case 0xC1: output = "Princess Ring"; break; // Casts "Protect" & "Shell" when near death
			case 0xC2: output = "Curse Ring"; break; // Is cursed
			case 0xC3: output = "Earring"; break; // Raises magical damage | Equip two to raise it further
			case 0xC4: output = "Giant Glove"; break; // Raises physical damage
			case 0xC5: output = "Storm Orb"; break; // If you equip this on a Yeti...
			case 0xC6: output = "Rage Ring"; break; // If you equip this on a Yeti...
			case 0xC7: output = "Thief Bangle"; break; // Raises success rate of "Steal"
			case 0xC8: output = "Defense Bangle"; break; // Automatically casts "Protect" & "Shell"
			case 0xC9: output = "Brave Ring"; break; // Raises physical & magical damage
			case 0xCA: output = "Ribbon"; break; // Prevents many status conditions
			case 0xCB: output = "Muscle Belt"; break; // Raises HP by 50%
			case 0xCC: output = "Crystal Orb"; break; // Raises MP by 50%
			case 0xCD: output = "Gold Hairpin"; break; // Reduces MP consumption to half normal
			case 0xCE: output = "Three Stars"; break; // Reduces MP consumption to 1
			case 0xCF: output = "Thief Glove"; break; // Changes the command "Steal" to "Mug"
			case 0xD0: output = "Gauntlet"; break; // Allows you to wield one weapon in two hands, increasing damage
			case 0xD1: output = "Genji Glove"; break; // Allows you to wield two weapons at once
			case 0xD2: output = "Hyper Wrist"; break; // Raises "Strength"
			case 0xD3: output = "Warrior's Proof"; break; // Causes "Frenzy" | Increases the number of attacks
			case 0xD4: output = "Abandon Beads"; break; // Randomly raises avoidance of enemy attacks
			case 0xD5: output = "Black Belt"; break; // Randomly counterattack when attacked by an enemy
			case 0xD6: output = "Heiji's Cross"; break; // Changes the command "Slot" to "Coin Toss"
			case 0xD7: output = "Dancho's Mustache"; break; // Changes the command "Sketch" to "Manipulate"
			case 0xD8: output = "Soul of Thamasa"; break; // Changes the command "Magic" to "Chained Magic"
			case 0xD9: output = "Flying Dragon Horn"; break; // Causes the "Jump" command to become continuous
			case 0xDA: output = "Medal"; break; // Allows the wearer to equip anything
			case 0xDB: output = "Memento Ring"; break; // Deceased mother's love protects against instant-death magic
			case 0xDC: output = "Safety Bit"; break; // Protects against instant-death magic
			case 0xDD: output = "Deceased Ring"; break; // Makes the body cold...
			case 0xDE: output = "Morul's Charm"; break; // Lowers the enemy encounters other than required ones to 0
			case 0xDF: output = "Repelling Bracelet"; break; // Reduces enemy counters other than required ones
			case 0xE0: output = "Miracle Shoes"; break; // Miraculous shoes which cause various effects
			case 0xE1: output = "Alarm Pierce"; break; // Back attacks & pincer attacks are avoided
			case 0xE2: output = "Gale Hairpin"; break; // Raises the probability of a pre-emptive attack
			case 0xE3: output = "Sniper Eye"; break; // Makes physical attacks always be 100% successful
			case 0xE4: output = "Grow Egg"; break; // Doubles the amount of experience earned after battles
			case 0xE5: output = "Cat's Bell"; break; // Recovers HP while walking
			case 0xE6: output = "Dash Shoes"; break; // Allows you to dash
			    //Miscellaneous
			case 0xE7: output = "Rename Card"; break; // Secret item
			case 0xE8: output = "Potion"; break; // Restores 50 HP
			case 0xE9: output = "High Potion"; break; // Restores 250 HP
			case 0xEA: output = "X-Potion"; break; // Restores all HP
			case 0xEB: output = "Ether"; break; // Restores 50 MP
			case 0xEC: output = "Turbo Ether"; break; // Restores 150 MP
			case 0xED: output = "Super Ether"; break; // Restore all MP
			case 0xEE: output = "Elixir"; break; // Restores all HP & MP
			case 0xEF: output = "Last Elixir"; break; // Restores all HP & MP to all alies
			case 0xF0: output = "Phoenix Down"; break; // Recovers from incapacitation
			case 0xF1: output = "Holy Water"; break; // Cures "Zombie" status
			case 0xF2: output = "Antidote"; break; // Cures "Poison" status
			case 0xF3: output = "Eye Drops"; break; // Cures "Darkness" status
			case 0xF4: output = "Golden Needle"; break; // Cures "Petrification" status
			case 0xF5: output = "Medicine"; break; // Cures all ailments, except "Zombie"
			case 0xF6: output = "Sleeping Bag"; break; // Lets one person rest & heal
			case 0xF7: output = "Tent"; break; // Rest a night to recover lost energy
			case 0xF8: output = "Yellow Cherry"; break; // Cures "Kappa" status
			case 0xF9: output = "Magirock Fragment"; break; // Summons a random Phantom Beast
			case 0xFA: output = "Super Ball"; break; // Bounces about, causing damage
			case 0xFB: output = "Echo Screen"; break; // Cures "Silence" status
			case 0xFC: output = "Smoke Ball"; break; // Makes the entire party escape from battle
			case 0xFD: output = "Teleport"; break; // Same effect as the spell "Teleport"
			case 0xFE: output = "Dried Meat"; break; // Eat it when you're hungry
			    //NOTHING
			case 0xFF: output = "EMPTY"; break;
		}
		return output;
    }

    public void fileWrite(int level, int curHP, int maxHP, int curMP, int maxMP, int exp, int strength, int speed, int vitality, int magic)
		throws IOException {
    	CharArray[8] = (byte) level;
		CharArray[9] = (byte)(curHP & 0xFF);
		CharArray[10] = (byte)((curHP  >> 8) & 0xFF);
		CharArray[11] = (byte)(maxHP & 0xFF);
		CharArray[12] = (byte)((maxHP >> 8) & 0xFF);
        CharArray[13] = (byte)(curMP & 0xFF);
		CharArray[14] = (byte)((curMP  >> 8) & 0xFF);
		CharArray[15] = (byte)(maxMP & 0xFF);
		CharArray[16] = (byte)((maxMP >> 8) & 0xFF);
		CharArray[17] = (byte)(exp & 0xFF);
		CharArray[18] = (byte)((exp >> 8) & 0xFF);
		CharArray[19] = (byte)((exp >> 16) & 0xFF);
		CharArray[26] = (byte)strength;
		CharArray[27] = (byte)speed;
		CharArray[28] = (byte)vitality;
		CharArray[29] = (byte)magic;

		file.seek(OFFSET + charOffset);
		file.write(CharArray);

		file.seek(GIL_OFFSET);
		file.write(gil);
    }

    public String getCommands(int n) {
    	String result = "";
    	if (n == 1)
    		result = CommandRead(CharArray[22]);
    	else if (n == 2)
    		result = CommandRead(CharArray[23]);
		else if (n == 3)
			result = CommandRead(CharArray[24]);
		else if (n == 4)
			result = CommandRead(CharArray[25]);

		return result;
    }

	public String CommandRead(byte b) {
		String result = "";
		switch(b) {
			case 0x00: result = "Fight"; break;
			case 0x01: result = "Item"; break;
			case 0x02: result = "Magic"; break;
			case 0x03: result = "Morph"; break;
			case 0x04: result = "Revert"; break;
			case 0x05: result = "Steal"; break;
			case 0x06: result = "Capture"; break;
			case 0x07: result = "Swdtech"; break;
			case 0x08: result = "Throw"; break;
			case 0x09: result = "Tools"; break;
			case 0x0A: result = "Blitz"; break;
			case 0x0B: result = "Runic"; break;
			case 0x0C: result = "Lore"; break;
			case 0x0D: result = "Sketch"; break;
			case 0x0E: result = "Control"; break;
			case 0x0F: result = "Slot"; break;
			case 0x10: result = "Rage"; break;
			case 0x11: result = "Leap"; break;
			case 0x12: result = "Mimic"; break;
			case 0x13: result = "Dance"; break;
			case 0x14: result = "Row"; break;
			case 0x15: result = "Defense"; break;
			case 0x16: result = "Jump"; break;
			case 0x17: result = "X-Magic"; break;
			case 0x18: result = "GP Rain"; break;
			case 0x19: result = "Summon"; break;
			case 0x1A: result = "Health"; break;
			case 0x1B: result = "Shock"; break;
			case 0x1C: result = "Possess"; break;
			case 0x1D: result = "MagiTek"; break;
			case 0x1E: result = "None"; break;
			default: result = "None"; break;
		}
		return result;
    }
}